﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using Microsoft.Samples.Kinect.WpfViewers;
using KinectDwa.Parsers.Helpers;
using KinectDwa;

namespace KinectApplication
{
    public static class Debugging
    {

        public static SmoothingParameters Smoothing = KinectDwa.SmoothingParameters.BalancedCorrection; // Balanced

        //set this to false to enable depth.dat file debugging
        public static bool LiveMode = true;

        //no debugging here, actual testing going on
        public static bool TestMode = true;

        //weird skele hand from the hand!
        public static bool SkeletonizeHandImage = true;

        //erosion image + better? x,y from hand image
        public static bool ErosionHandImage = true;

        //erosion first, then some buffing up = smoother image?
        public static bool ErosionAndDilatation = true;

        //fancy way to get some important hand points?
        public static bool FindQuadrilateralCorners = true;

        public static bool ShowDepthData = true;

        public static KinectDiagnosticViewer view;

        //public static void ShowDepth(byte[] source, int width, int height)
        //{
        //    byte[] depth = source.ConvertDepthFrameDataToBitmapData(width, height);
        //    image.Source = depth.ToBitmapSource(width, height);
        //}

        //public static void ShowDepth(short[] source, int width, int height)
        //{
        //    byte[] depth = source.ConvertDepthFrameDataToBitmapData(width, height);
        //    image.Source = depth.ToBitmapSource(width, height);
        //}

        //public static void ShowDepthWithPlayer(byte[] source, int width, int height)
        //{
        //    byte[] depth = source.ConvertDepthFrameDataWithSkeletonToBitmapData(width, height);
        //    image.Source = depth.ToBitmapSource(width, height);
        //}


        public static void ShowText(string text)
        {
            if (TestMode == false)
            {
                view.textbox.Text = text;
            }
        }

   

        public static void ShowRectangle(int x, int y, int width, int height, Color color)
        {
            if (TestMode == false)
            {

                Rectangle r = new Rectangle();
                r.Width = width;
                r.Height = height;
                r.Stroke = new SolidColorBrush(color);
                r.StrokeThickness = 3.0D;
                view.canvas.Children.Add(r);

                Canvas.SetLeft(r, x);
                Canvas.SetTop(r, y);
            }
        }

        public static void ShowPointInHandImage(int x, int y, Color color)
        {
            if (TestMode == false)
            {
                Rectangle r = new Rectangle();
                r.Width = 6;
                r.Height = 6;
                r.Stroke = new SolidColorBrush(color);
                r.StrokeThickness = 3.0D;
                view.handCanvas.Children.Add(r);

                Canvas.SetLeft(r, x - 3);
                Canvas.SetTop(r, y - 3);
            }
        }

        public static void ShowPointInSkeleHandImage(int x, int y, Color color)
        {
            if (TestMode == false)
            {
                Rectangle r = new Rectangle();
                r.Width = 6;
                r.Height = 6;
                r.Stroke = new SolidColorBrush(color);
                r.StrokeThickness = 3.0D;
                view.skeleCanvas.Children.Add(r);

                Canvas.SetLeft(r, x - 3);
                Canvas.SetTop(r, y - 3);
            }
        }

        public static void ShowPoint(int x, int y, Color color)
        {
            if (TestMode == false)
            {
                Rectangle r = new Rectangle();
                r.Width = 8;
                r.Height = 8;
                r.Stroke = new SolidColorBrush(color);
                r.StrokeThickness = 3.0D;
                view.canvas.Children.Add(r);

                Canvas.SetLeft(r, x - 4);
                Canvas.SetTop(r, y - 4);
            }
        }

        public static void ShowRectangle(int x, int y, int width, int height)
        {

            if (TestMode == false)
            {
                Rectangle r = new Rectangle();
                r.Width = width;
                r.Height = height;
                r.Stroke = new SolidColorBrush(Colors.Green);
                view.canvas.Children.Add(r);

                Canvas.SetLeft(r, x);
                Canvas.SetTop(r, y);
            }
        }

        public static void ShowHand(int Width, int Height, int X, int Y)
        {

            if (TestMode == false)
            {
                Rectangle r = new Rectangle();
                r.Width = Width;
                r.Height = Height;
                r.Stroke = new SolidColorBrush(Colors.Red);
                r.Fill = new SolidColorBrush(Colors.Red);
                view.canvas.Children.Add(r);

                Canvas.SetLeft(r, X - (Width / 2));
                Canvas.SetTop(r, Y - (Height / 2));
            }
        }

        public static void ShowHandImages(HandInfo info)
        {
            if (TestMode == false)
            {
                view.KinectHandViewer.ShowHand(info.HandArray, info.RotatedHandWidth, info.RotatedHandHeight);
                view.KinectResizedHandViewer.ShowHand(info.ResizedArray, HandGestureReader.PicWidth, HandGestureReader.PicHeight);
                // view.KinectHandSkeleViewer.ShowHand(info.SkeleArray, info.RotatedHandWidth, info.RotatedHandHeight);
                // view.KinectHandErosionViewer.ShowHand(info.ErosionArray, info.RotatedHandWidth, info.RotatedHandHeight);
            }
        }


        public static void Clear()
        {
            if (TestMode == false)
            {
                view.canvas.Children.Clear();
                view.handCanvas.Children.Clear();
                view.skeleCanvas.Children.Clear();
            }
        }


        public static void ShowXY(int x, int y)
        {

            if (TestMode == false)
            {
                Rectangle r = new Rectangle();
                r.Width = 10;
                r.Height = 10;
                r.Stroke = new SolidColorBrush(Colors.Red);
                view.canvas.Children.Add(r);

                Canvas.SetLeft(r, x - 5);
                Canvas.SetTop(r, y - 5);

            }
        }


    }
}
